package com.bjesc_b2c.app.appraiset.mvp.view.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.bjesc_b2c.app.appraiset.R;
import com.bjesc_b2c.app.appraiset.base.BaseFragmentActivity;
import com.bjesc_b2c.app.appraiset.mvp.view.fragment.CarEngineFragment;
import com.bjesc_b2c.app.appraiset.mvp.view.fragment.CarOrnamentsPhotoFragment;
import com.bjesc_b2c.app.appraiset.mvp.view.fragment.CarProceduresFragment;
import com.bjesc_b2c.app.appraiset.mvp.view.fragment.CarSurfacePhotoFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import rxbus_base.RxBus;

/**
 * Created by lenovo on 2017/2/24.
 */

public class CarSourceActivity extends BaseFragmentActivity implements View.OnClickListener {

    @Bind(R.id.line_1)
    View oneLineView;
    @Bind(R.id.line_2)
    View twoLineView;
    @Bind(R.id.line_3)
    View threeLineView;
    @Bind(R.id.line_4)
    View fourLineView;
    @Bind(R.id.tv_car_surface)
    TextView surfaceTv;
    @Bind(R.id.tv_car_ornaments)
    TextView ornamentsTv;
    @Bind(R.id.tv_car_engine)
    TextView engineTv;
    @Bind(R.id.tv_car_procedures)
    TextView proceduresTv;
    private List<View> views;
    private List<TextView> texts;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_car_source);
        ButterKnife.bind(this);
        getLineList();
        switch(getIntent().getIntExtra("switch",0)){
            case 0:
                switchContent(CarSurfacePhotoFragment.class, R.id.framen_car_source);
                changeViewColor(oneLineView);
                break;
            case 1:
                switchContent(CarOrnamentsPhotoFragment.class, R.id.framen_car_source);
                changeViewColor(twoLineView);
                break;
            case 2:
                switchContent(CarEngineFragment.class, R.id.framen_car_source);
                changeViewColor(threeLineView);
                break;
            case 3:
                switchContent(CarProceduresFragment.class, R.id.framen_car_source);
                changeViewColor(fourLineView);
                break;
        }
    }

    private void getLineList() {
        views = new ArrayList<>();
        texts = new ArrayList<>();
        views.add(oneLineView);
        views.add(twoLineView);
        views.add(threeLineView);
        views.add(fourLineView);
        texts.add(surfaceTv);
        texts.add(ornamentsTv);
        texts.add(engineTv);
        texts.add(proceduresTv);
    }

    @OnClick({R.id.rl_return, R.id.tv_save_info, R.id.tv_car_surface, R.id.tv_car_ornaments, R.id.tv_car_engine,
            R.id.tv_car_procedures, R.id.btn_previous_page, R.id.tv_title})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.rl_return:    //返回
                setResult(101);
                finish();
                break;
            case R.id.tv_save_info:
                RxBus.getInstance().sendData(indexfragment.getClass().getName(),null);
                break;
            case R.id.tv_car_surface:     //外观
                switchContent(CarSurfacePhotoFragment.class, R.id.framen_car_source);
                changeViewColor(oneLineView);
                break;
            case R.id.tv_car_ornaments:     //内饰
                switchContent(CarOrnamentsPhotoFragment.class, R.id.framen_car_source);
                changeViewColor(twoLineView);
                break;
            case R.id.tv_car_engine:        //发动机
                switchContent(CarEngineFragment.class, R.id.framen_car_source);
                changeViewColor(threeLineView);
                break;
            case R.id.tv_car_procedures:    //手续
                switchContent(CarProceduresFragment.class, R.id.framen_car_source);
                changeViewColor(fourLineView);
                break;
        }
    }
    //按钮选项
    public void changeViewColor(View v) {
        for (int i = 0; i < views.size(); i++) {
            if (v == views.get(i)) {
                views.get(i).setBackgroundResource(R.color.colorFFFF7900);
                texts.get(i).setTextColor(getResources().getColor(R.color.colorFFFF7900));
            } else {
                views.get(i).setBackgroundResource(R.color.colorLine);
                texts.get(i).setTextColor(getResources().getColor(R.color.colorFF030303));
            }
        }
    }

    @Override
    public void onBackPressed() {//返回键
        setResult(101);
        finish();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        ButterKnife.unbind(this);
    }
}
